﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Kugar.Core.ExtMethod;
using Kugar.UI.Web.AdminLTE.Helpers;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Kugar.UI.Web.AdminLTE.PageControls.PageForms
{
    public class PageForm_TextareaField: PageForm_SingleInputFieldBase
    {
        //private string _name = "";
        private string _value = "";
        private bool _disabled;
        private string _placeholder = "";
        private bool _readonly = false;
        private int _maxLength = -1;
        private int _rows = 5;

        public PageForm_TextareaField(IPageForm form, ViewContext viewContext) : base((PageForm_Form)form, viewContext)
        {
            this.Css("webui-form_textareafield");
        }

        public PageForm_TextareaField Value(string value)
        {
            _value = value;

            return this;
        }

        //public PageForm_TextareaField Name(string name)
        //{
        //    _name = name;

        //    return this;
        //}

        public PageForm_TextareaField Placeholder(string text)
        {
            _placeholder = text;

            return this;
        }

        public PageForm_TextareaField ReadOnly(bool isReadOnly = true)
        {
            _readonly = isReadOnly;

            return this;
        }

        public PageForm_TextareaField MaxLength(int maxLength)
        {
            _maxLength = maxLength;

            return this;
        }

        public PageForm_TextareaField Rows(int row)
        {
            _rows = row;

            return this;
        }

        public PageForm_TextareaField Disabled(bool disabled = true)
        {
            _disabled = disabled;

            return this;
        }

        protected override void RenderContent(TextWriter writer)
        {
            writer.WriteLine($"<textarea type=\"text\" rows=\"{_rows}\"  {(_isRequired ? "required" : "")} name=\"{_name}\" lay-ignore class=\"form-control \" {_readonly.If("readonly")} {(_maxLength > 0).If($"maxlength=\"{_maxLength}\"")} {_isRequired.If("required")} placeholder=\"{_placeholder}\" {_disabled.If("disabled")} >{_value}</textarea>");
        }
    }
}
